import React, { useState, useEffect } from 'react'
import Head from 'next/head'
import { Row, Col, List } from 'antd'
import Header from '../components/Header'
import "../static/style/pages/index.less"
import Author from '../components/Author'
import Advert from '../components/Advert'
import Footer from '../components/Footer'
import MyList from '../components/MyList'
import servicePath from '../config/apiUrl'

const that = React;

const Home = (props) => {
  console.log("start==", props);
  const [mylist, setMylist] = useState(props.data)

  useEffect(() => {
    console.log('这是在渲染，只运行这一次', React, "this=", this, "props", props);
    return () => {
      console.log('Test组件死了', React, "this=", this, "props", props);
    }
  });

  return (
    <div>
      <Head>
        <title>Home</title>
      </Head>
      <Header />
      <Row className="comm-main" type="flex" justify="center">
        <Col className="comm-left" xs={24} sm={24} md={16} lg={18} xl={14}  >
          <MyList header={<div>最新日志</div>} itemLayout="vertical" bordered dataSource={mylist} />
        </Col>

        <Col className="comm-right" xs={0} sm={0} md={7} lg={5} xl={4}>
          <Author />
          <Advert />
        </Col>
      </Row>
      <Footer />
    </div>
  )
}

Home.getInitialProps = async (ctx) => {
  // console.log("this==getInitialProps",ctx)
  const result = new Promise((resolve) => {
    that.$http(servicePath.getArticleList).then(res => {
      console.log('远程获取数据结果:', res.data.data)
      resolve(res.data)
    })
  })
  console.log("typeof--Home-result",typeof result)
  return await result
}


export default Home